package com.yswy.backstage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yswy.backstage.service.AppProjectService;
import com.yswy.backstage.service.PackageVersionService;
import com.yswy.domain.entity.AppProject;
import com.yswy.domain.entity.PackageVersion;
import com.yswy.domain.entity.user.User;
import com.yswy.domain.vo.dto.BaseFilter;
import com.yswy.domain.vo.gld.addOrUpate.AppProjectAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.PackageVersionAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.base.BaseReqVO;
import com.yswy.domain.vo.gld.list.PackageManageLogList;
import com.yswy.domain.vo.gld.search.PackageManageIdSearch;
import com.yswy.domain.vo.gld.search.PackageVersionSearch;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

import java.util.List;

import static com.yswy.backstage.utils.GldTokenUtils.getUser;


@RestController
@RequestMapping("/packageVersion")
@Api(tags = "版本管理")
public class PackageVersionController {
    @Autowired
    private PackageVersionService packageVersionService;

    @PostMapping("/listPackageVersion")
    @ApiOperation(value = "查询版本管理")
    public Page<PackageVersion> listPackageVersion(@RequestBody  PackageVersionSearch req, HttpServletRequest request) {
        return packageVersionService.listPackageVersion(req);
    }

    @PostMapping("/addPackageVersion")
    @ApiOperation(value = "新增版本管理")
    public void addPackageVersion(@ModelAttribute @Validated(BaseReqVO.CREATE.class) PackageVersionAddOrUpdate req, HttpServletRequest request) {
        packageVersionService.addOrUpdatePackageVersion(req);
    }

    @PostMapping("/updatePackageVersion")
    @ApiOperation(value = "修改版本管理")
    public void updatePackageVersion(@ModelAttribute @Validated(BaseReqVO.UPDATE.class) PackageVersionAddOrUpdate req, HttpServletRequest request) {
        packageVersionService.addOrUpdatePackageVersion(req);
    }

    @GetMapping("/updateisRelease")
    @ApiOperation(value = "发布")
    public void updateisRelease(@RequestParam(value = "projectId") Long packageVersionId
            ,@RequestParam(value = "isRelease") Integer isRelease  , HttpServletRequest request) {
        packageVersionService.updateisRelease(packageVersionId, isRelease);
    }

    @GetMapping("/isExistVersion")
    @ApiOperation(value = "版本是否存在")
    public Boolean isExistVersion(@RequestParam(value = "projectId") Long projectId ,
                               @RequestParam(value = "versionCode")String versionCode  ,
                               HttpServletRequest request) {
       return packageVersionService.isExistVersion(projectId, versionCode);
    }

    @GetMapping("/delPackageVersion")
    @ApiOperation(value = "删除版本管理")
    public void delPackageVersion(@RequestParam(value = "packageVersionId") Long packageVersionId
            , HttpServletRequest request) {
        packageVersionService.delPackageVersion(packageVersionId);
    }

    @GetMapping("/getVersionByProjectId")
    @ApiOperation(value = "根据项目获取版本列表")
    public void getVersionByProjectId(@RequestParam(value = "projectId") Long projectId
            , HttpServletRequest request) {
        packageVersionService.getVersionByProjectId(projectId);
    }

}
